<?php $this->fetch('public/head') ?>
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">信息列表</li>
    </ul>
    <div class="layui-tab-content">
        <div id="ss" class="layui-form layui-form-pane">
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select name="status" lay-filter="query" class="query">
                        <option value="">全部</option>
                        <?php foreach ($status as $k => $v): ?>
                            <option value="<?php echo $k ?>"><?php echo $v ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline">
                    <select name="complete_type" lay-filter="query" class="query">
                        <option value="">全部</option>
                        <?php foreach ($cate as $k => $v): ?>
                            <option value="<?php echo $k ?>" <?php if (input('nid') == $k) {
                                echo 'selected="selected"';
                            } ?>><?php echo $v ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">关键词</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" value="<?php echo input('title') ?>" placeholder="请输入关键词"
                           class="layui-input query">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">提交时间</label>
                <div class="layui-input-block">
                    <input type="text"  value="" lay-verify="begin_time"
                           class="layui-input  begin_time query">
                    <input type="hidden" value="" name="begin_time" id="begin_time" class="query">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">审核通过时间</label>
                <div class="layui-input-block">
                    <input type="text"  value="" lay-verify="end_time"
                           class="layui-input approval_time query">
                    <input type="hidden" value="" name="approval_time" id="approval_time" class="query">
                </div>
            </div>



            <div class="layui-inline">
                <label class="layui-form-label">完成时间</label>
                <div class="layui-input-block">
                    <input type="text"  value="" lay-verify="end_time"
                           class="layui-input finishe_time query">
                    <input type="hidden" value="" name="finishe_time" id="finishe_time" class="query">
                </div>
            </div>
        </div>
        <div class="layui-inline">
            <a class="layui-btn" onclick="get_excel()">导出</a>
        </div>
        <hr>

        <div class="layui-tab-item layui-show">
            <table id="dataList" lay-filter="dataList" class="layui-hide"></table>
        </div>
    </div>
</div>
<?php $this->fetch('public/script') ?>

<script>

    let cate = <?php echo $cate?json_encode($cate):[]?>;
    function get_excel(){
        let params = HS.getParams('.query');
        var _href = HS.U('<?php echo url('output')?>',params);
        layer.confirm('您确定要导出当前查询结果吗？', {
            btn: ['导出','再看看'] //按钮
        }, function(){
            layer.msg('请稍等', {icon: 1});
            location.href = _href;
        }, function(){
            layer.msg('取消导出');
        });
        return false;
    }
    function get_excel_o(){
        let params = HS.getParams('.query');
        var _href = HS.U('<?php echo url('output_o')?>',params);
        layer.confirm('您确定要导出当前查询结果吗？', {
            btn: ['导出','再看看'] //按钮
        }, function(){
            layer.msg('请稍等', {icon: 1});
            location.href = _href;
        }, function(){
            layer.msg('取消导出');
        });
        return false;
    }
    layui.use(['table', 'laydate'], function () {
        var table = layui.table
            , form = layui.form,
            laydate = layui.laydate;
        laydate.render({
            elem: '.begin_time'
            , type: 'datetime'   //年月日时间
            ,range:"~"
            , done: function (data) {
                $('#begin_time').val(data);
                getLists();
            }

        });
        laydate.render({
            elem: '.approval_time'
            , type: 'datetime'   //年月日时间
            ,range:"~"
            , done: function (data) {
                $('#approval_time').val(data);
                getLists();
            }
        });
        laydate.render({
            elem: '.finishe_time'
            , type: 'datetime'   //年月日时间
            ,range:"~"
            , done: function (data) {
                $('#finishe_time').val(data);
                getLists();
            }
        });
        getLists();
        form.on('select(query)', function (data) {
            $(data.elem).trigger('change', data.elem); //此处可让select支持change事件，trigger方法触发被选元素的指定事件类型。
        });
        //改变查询条件后重新获取列表数据
        $('.query').change(function () {
            getLists();
        });

        function getLists() {
            let params = HS.getParams('.query');
            //数据表格
            let load_table = layer.load(0, {time: 30000});
            table.render({
                elem: '#dataList'
                , height: $(window).height() - 155
                , url: '<?php echo url('getLists') ?>' //数据接口
                , method: 'post'
                , where: params
                , response: {
                    countName: 'total' //数据总数的字段名称，默认：count
                }
                , page: {
                    limit: 20
                    , limits: [20, 30, 50, 100]
                    , groups: 5
                    , layout: ['prev', 'page', 'next', 'limit', 'refresh', 'skip', 'count']
                } //开启分页
                , defaultToolbar: ['filter']    //, 'print', 'exports'
                , cols: [[ //表头
                    {field: 'id', title: 'ID', width: 50, event: 'detail'}
                    , {field: 'title', title: '标题',  event: 'detail'}
                    , {field: 'user_name', title: '提议人',templet:function (d) {
                            return d.create_user_info.name
                        }}
                    , {field: 'question_classfy', title: '问题类型',templet:function (d) {
                            return cate[d.propsoe_type]
                        }}
                    , {field: 'add_time', title: '添加时间', event: 'detail'}
                    , {
                        title: '详情',  templet: function (d) {
                            var html = '';
                            return '<div><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">详情</a>'
                                +'<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="change">修改状态</a>'+html
                            +'</div>'
                        }, event: 'detail'
                    }
                ]]
                , text: {none: '暂无相关数据'}
                , done: function (res, curr, count) {
                    layer.close(load_table);
                }
            })
        }

        //监听工具条
        table.on('tool(dataList)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            //var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'edit') { //编辑
                layer.open({
                    type: 2,
                    title: '详情',
                    area: ['80%', '80%'],
                    content: HS.U('/admin/propose/detail', {id: data.id})
                })
            }else if(layEvent === 'undo') { //编辑
                layer.confirm('请确认提议已经完成', {
                    btn: ['确认', '取消'] //按钮
                }, function () {
                    $.ajax({
                        url:"<?php echo url('undo')?>",
                        data:{id:data.id},
                        success:function (data) {
                            layer.msg(data.msg);
                        }
                    })
                }, function () {
                    layer.msg('取消成功');
                });

            }else if(layEvent==='change'){
                layer.open({
                    type:2,
                    title:'修改状态',
                    area:['80%','80%'],
                    content:HS.U('/admin/propose/changes_status',{id:data.id}),
                })
            }
        });
        //显示/隐藏、置顶操作
    });
</script>